package com.dingup.homework.feign.server.mock;

import com.dingup.homework.enums.HomeworkStatusEnum;
import com.dingup.homework.enums.QuestionTypeEnum;
import com.dingup.homework.service.TeacherCorrectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by wancheng on 2018/11/12.
 */
@RestController()
@RequestMapping("/feign/correct")
public class TeacherCorrectFeign {

    private static Logger logger = LoggerFactory.getLogger(TeacherCorrectFeign.class);

    @Autowired
    TeacherCorrectService teacherCorrectService;

    @RequestMapping(value = "/update_teacher_correct.do", method = RequestMethod.POST)
    public void updateTeacherCorrect(@RequestParam("homeworkRecordId") Integer homeworkRecordId,
                                     @RequestParam("examId") String examId,
                                     @RequestParam("examIdentity") Integer examIdentity,
                                     @RequestParam("endTime") Date endTime) {
        try {
            logger.info("save_teacher_correct.do  homeworkRecordId={},examId={},examIdentity={},endTime={}", homeworkRecordId, examId, examIdentity, endTime);
            teacherCorrectService.updateWhenStudentFinish(homeworkRecordId, examId, examIdentity, endTime, null);
        } catch (Exception e) {
            logger.error("save_teacher_correct error Exception={}", e.getMessage());
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/update_correct_homework_status.do", method = RequestMethod.POST)
    public void updateCorrectHomeworkStatus(@RequestParam("homeworkRecordId") Integer homeworkRecordId,
                                            @RequestParam("type") QuestionTypeEnum type) {
        try {
            logger.info("update_correct_homework_status.do  homeworkRecordId={}", homeworkRecordId);
            teacherCorrectService.updateCorrectHomeworkStatus(homeworkRecordId, type, HomeworkStatusEnum.CORRECTED);
        } catch (Exception e) {
            logger.error("update_correct_homework_status error Exception={}", e.getMessage());
            e.printStackTrace();
        }
    }
}
